home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ZSI / wstools / WSDLTools.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2008-10-13  |  50.7 KB  |  1,719 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. ident = '$Id: WSDLTools.py 1122 2006-02-04 01:24:50Z boverhof $'
  5. import weakref
  6. from cStringIO import StringIO
  7. from Namespaces import OASIS, XMLNS, WSA, WSA_LIST, WSRF_V1_2, WSRF
  8. from Utility import Collection, CollectionNS, DOM, ElementProxy, basejoin
  9. from XMLSchema import XMLSchema, SchemaReader, WSDLToolsAdapter
  10.  
  11. class WSDLReader:
  12.     
  13.     def loadFromStream(self, stream, name = None):
  14.         document = DOM.loadDocument(stream)
  15.         wsdl = WSDL()
  16.         if name:
  17.             wsdl.location = name
  18.         elif hasattr(stream, 'name'):
  19.             wsdl.location = stream.name
  20.         
  21.         wsdl.load(document)
  22.         return wsdl
  23.  
  24.     
  25.     def loadFromURL(self, url):
  26.         document = DOM.loadFromURL(url)
  27.         wsdl = WSDL()
  28.         wsdl.location = url
  29.         wsdl.load(document)
  30.         return wsdl
  31.  
  32.     
  33.     def loadFromString(self, data):
  34.         return self.loadFromStream(StringIO(data))
  35.  
  36.     
  37.     def loadFromFile(self, filename):
  38.         file = open(filename, 'rb')
  39.         
  40.         try:
  41.             wsdl = self.loadFromStream(file)
  42.         finally:
  43.             file.close()
  44.  
  45.         return wsdl
  46.  
  47.  
  48.  
  49. class WSDL:
  50.     
  51.     def __init__(self, targetNamespace = None, strict = 1):
  52.         if not targetNamespace:
  53.             pass
  54.         self.targetNamespace = 'urn:this-document.wsdl'
  55.         self.documentation = ''
  56.         self.location = None
  57.         self.document = None
  58.         self.name = None
  59.         self.services = CollectionNS(self)
  60.         self.messages = CollectionNS(self)
  61.         self.portTypes = CollectionNS(self)
  62.         self.bindings = CollectionNS(self)
  63.         self.imports = Collection(self)
  64.         self.types = Types(self)
  65.         self.extensions = []
  66.         self.strict = strict
  67.  
  68.     
  69.     def __del__(self):
  70.         if self.document is not None:
  71.             self.document.unlink()
  72.         
  73.  
  74.     version = '1.1'
  75.     
  76.     def addService(self, name, documentation = '', targetNamespace = None):
  77.         if self.services.has_key(name):
  78.             raise WSDLError('Duplicate service element: %s' % name)
  79.         
  80.         item = Service(name, documentation)
  81.         if targetNamespace:
  82.             item.targetNamespace = targetNamespace
  83.         
  84.         self.services[name] = item
  85.         return item
  86.  
  87.     
  88.     def addMessage(self, name, documentation = '', targetNamespace = None):
  89.         if self.messages.has_key(name):
  90.             raise WSDLError('Duplicate message element: %s.' % name)
  91.         
  92.         item = Message(name, documentation)
  93.         if targetNamespace:
  94.             item.targetNamespace = targetNamespace
  95.         
  96.         self.messages[name] = item
  97.         return item
  98.  
  99.     
  100.     def addPortType(self, name, documentation = '', targetNamespace = None):
  101.         if self.portTypes.has_key(name):
  102.             raise WSDLError('Duplicate portType element: name')
  103.         
  104.         item = PortType(name, documentation)
  105.         if targetNamespace:
  106.             item.targetNamespace = targetNamespace
  107.         
  108.         self.portTypes[name] = item
  109.         return item
  110.  
  111.     
  112.     def addBinding(self, name, type, documentation = '', targetNamespace = None):
  113.         if self.bindings.has_key(name):
  114.             raise WSDLError('Duplicate binding element: %s' % name)
  115.         
  116.         item = Binding(name, type, documentation)
  117.         if targetNamespace:
  118.             item.targetNamespace = targetNamespace
  119.         
  120.         self.bindings[name] = item
  121.         return item
  122.  
  123.     
  124.     def addImport(self, namespace, location):
  125.         item = ImportElement(namespace, location)
  126.         self.imports[namespace] = item
  127.         return item
  128.  
  129.     
  130.     def toDom(self):
  131.         namespaceURI = DOM.GetWSDLUri(self.version)
  132.         self.document = DOM.createDocument(namespaceURI, 'wsdl:definitions')
  133.         child = DOM.getElement(self.document, None)
  134.         child.setAttributeNS(None, 'targetNamespace', self.targetNamespace)
  135.         child.setAttributeNS(XMLNS.BASE, 'xmlns:wsdl', namespaceURI)
  136.         child.setAttributeNS(XMLNS.BASE, 'xmlns:xsd', 'http://www.w3.org/1999/XMLSchema')
  137.         child.setAttributeNS(XMLNS.BASE, 'xmlns:soap', 'http://schemas.xmlsoap.org/wsdl/soap/')
  138.         child.setAttributeNS(XMLNS.BASE, 'xmlns:tns', self.targetNamespace)
  139.         if self.name:
  140.             child.setAttributeNS(None, 'name', self.name)
  141.         
  142.         for item in self.imports:
  143.             item.toDom()
  144.         
  145.         for item in self.messages:
  146.             item.toDom()
  147.         
  148.         for item in self.portTypes:
  149.             item.toDom()
  150.         
  151.         for item in self.bindings:
  152.             item.toDom()
  153.         
  154.         for item in self.services:
  155.             item.toDom()
  156.         
  157.  
  158.     
  159.     def load(self, document):
  160.         self.document = document
  161.         definitions = DOM.getElement(document, 'definitions', None, None)
  162.         if definitions is None:
  163.             raise WSDLError('Missing <definitions> element.')
  164.         
  165.         self.version = DOM.WSDLUriToVersion(definitions.namespaceURI)
  166.         NS_WSDL = DOM.GetWSDLUri(self.version)
  167.         self.targetNamespace = DOM.getAttr(definitions, 'targetNamespace', None, None)
  168.         self.name = DOM.getAttr(definitions, 'name', None, None)
  169.         self.documentation = GetDocumentation(definitions)
  170.         imported = []
  171.         base_location = self.location
  172.         do_it = True
  173.         while do_it:
  174.             do_it = False
  175.             for element in DOM.getElements(definitions, 'import', NS_WSDL):
  176.                 location = DOM.getAttr(element, 'location')
  177.                 if base_location is not None:
  178.                     location = basejoin(base_location, location)
  179.                 
  180.                 if location not in imported:
  181.                     do_it = True
  182.                     self._import(document, element, base_location)
  183.                     imported.append(location)
  184.                     continue
  185.                 definitions.removeChild(element)
  186.             
  187.             base_location = None
  188.         for element in DOM.getElements(definitions, None, None):
  189.             targetNamespace = DOM.getAttr(element, 'targetNamespace')
  190.             localName = element.localName
  191.             if not DOM.nsUriMatch(element.namespaceURI, NS_WSDL):
  192.                 if localName == 'schema':
  193.                     tns = DOM.getAttr(element, 'targetNamespace')
  194.                     reader = SchemaReader(base_url = self.imports[tns].location)
  195.                     schema = reader.loadFromNode(WSDLToolsAdapter(self), element)
  196.                     self.types.addSchema(schema)
  197.                     continue
  198.                 self.extensions.append(element)
  199.                 continue
  200.                 continue
  201.             if localName == 'message':
  202.                 name = DOM.getAttr(element, 'name')
  203.                 docs = GetDocumentation(element)
  204.                 message = self.addMessage(name, docs, targetNamespace)
  205.                 parts = DOM.getElements(element, 'part', NS_WSDL)
  206.                 message.load(parts)
  207.                 continue
  208.                 continue
  209.             if localName == 'portType':
  210.                 name = DOM.getAttr(element, 'name')
  211.                 docs = GetDocumentation(element)
  212.                 ptype = self.addPortType(name, docs, targetNamespace)
  213.                 ptype.load(element)
  214.                 continue
  215.                 continue
  216.             if localName == 'binding':
  217.                 name = DOM.getAttr(element, 'name')
  218.                 type = DOM.getAttr(element, 'type', default = None)
  219.                 if type is None:
  220.                     raise WSDLError('Missing type attribute for binding %s.' % name)
  221.                 
  222.                 type = ParseQName(type, element)
  223.                 docs = GetDocumentation(element)
  224.                 binding = self.addBinding(name, type, docs, targetNamespace)
  225.                 operations = DOM.getElements(element, 'operation', NS_WSDL)
  226.                 binding.load(operations)
  227.                 binding.load_ex(GetExtensions(element))
  228.                 continue
  229.                 continue
  230.             if localName == 'service':
  231.                 name = DOM.getAttr(element, 'name')
  232.                 docs = GetDocumentation(element)
  233.                 service = self.addService(name, docs, targetNamespace)
  234.                 ports = DOM.getElements(element, 'port', NS_WSDL)
  235.                 service.load(ports)
  236.                 service.load_ex(GetExtensions(element))
  237.                 continue
  238.                 continue
  239.             if localName == 'types':
  240.                 self.types.documentation = GetDocumentation(element)
  241.                 base_location = DOM.getAttr(element, 'base-location')
  242.                 if base_location:
  243.                     element.removeAttribute('base-location')
  244.                 
  245.                 if not base_location:
  246.                     pass
  247.                 base_location = self.location
  248.                 reader = SchemaReader(base_url = base_location)
  249.                 for item in DOM.getElements(element, None, None):
  250.                     if item.localName == 'schema':
  251.                         schema = reader.loadFromNode(WSDLToolsAdapter(self), item)
  252.                         schema.setBaseUrl(base_location)
  253.                         self.types.addSchema(schema)
  254.                         continue
  255.                     self.types.addExtension(item)
  256.                 
  257.                 continue
  258.                 continue
  259.         
  260.  
  261.     
  262.     def _import(self, document, element, base_location = None):
  263.         namespace = DOM.getAttr(element, 'namespace', default = None)
  264.         location = DOM.getAttr(element, 'location', default = None)
  265.         if namespace is None or location is None:
  266.             raise WSDLError('Invalid import element (missing namespace or location).')
  267.         
  268.         if base_location:
  269.             location = basejoin(base_location, location)
  270.             element.setAttributeNS(None, 'location', location)
  271.         
  272.         obimport = self.addImport(namespace, location)
  273.         obimport._loaded = 1
  274.         importdoc = DOM.loadFromURL(location)
  275.         
  276.         try:
  277.             if location.find('#') > -1:
  278.                 idref = location.split('#')[-1]
  279.                 imported = DOM.getElementById(importdoc, idref)
  280.             else:
  281.                 imported = importdoc.documentElement
  282.             if imported is None:
  283.                 raise WSDLError('Import target element not found for: %s' % location)
  284.             
  285.             imported_tns = DOM.findTargetNS(imported)
  286.             if imported_tns != namespace:
  287.                 return None
  288.             
  289.             if imported.localName == 'definitions':
  290.                 imported_nodes = imported.childNodes
  291.             else:
  292.                 imported_nodes = [
  293.                     imported]
  294.             parent = element.parentNode
  295.             parent.removeChild(element)
  296.             for node in imported_nodes:
  297.                 if node.nodeType != node.ELEMENT_NODE:
  298.                     continue
  299.                 
  300.                 child = DOM.importNode(document, node, 1)
  301.                 parent.appendChild(child)
  302.                 child.setAttribute('targetNamespace', namespace)
  303.                 attrsNS = imported._attrsNS
  304.                 for attrkey in attrsNS.keys():
  305.                     if attrkey[0] == DOM.NS_XMLNS:
  306.                         attr = attrsNS[attrkey].cloneNode(1)
  307.                         child.setAttributeNode(attr)
  308.                         continue
  309.                 
  310.                 if child.localName == 'import':
  311.                     rlocation = child.getAttributeNS(None, 'location')
  312.                     alocation = basejoin(location, rlocation)
  313.                     child.setAttribute('location', alocation)
  314.                     continue
  315.                 if child.localName == 'types':
  316.                     child.setAttribute('base-location', location)
  317.                     continue
  318.         finally:
  319.             importdoc.unlink()
  320.  
  321.         return location
  322.  
  323.  
  324.  
  325. class Element:
  326.     
  327.     def __init__(self, name = None, documentation = ''):
  328.         self.name = name
  329.         self.documentation = documentation
  330.         self.extensions = []
  331.  
  332.     
  333.     def addExtension(self, item):
  334.         item.parent = weakref.ref(self)
  335.         self.extensions.append(item)
  336.  
  337.     
  338.     def getWSDL(self):
  339.         parent = self
  340.         while isinstance(parent, WSDL):
  341.             return parent
  342.         
  343.         try:
  344.             parent = parent.parent()
  345.         continue
  346.         break
  347.         continue
  348.  
  349.         continue
  350.  
  351.  
  352.  
  353. class ImportElement(Element):
  354.     
  355.     def __init__(self, namespace, location):
  356.         self.namespace = namespace
  357.         self.location = location
  358.  
  359.     
  360.     def toDom(self):
  361.         wsdl = self.getWSDL()
  362.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  363.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'import')
  364.         epc.setAttributeNS(None, 'namespace', self.namespace)
  365.         epc.setAttributeNS(None, 'location', self.location)
  366.  
  367.     _loaded = None
  368.  
  369.  
  370. class Types(Collection):
  371.     
  372.     default = lambda self, k: k.targetNamespace
  373.     
  374.     def __init__(self, parent):
  375.         Collection.__init__(self, parent)
  376.         self.documentation = ''
  377.         self.extensions = []
  378.  
  379.     
  380.     def addSchema(self, schema):
  381.         name = schema.targetNamespace
  382.         self[name] = schema
  383.         return schema
  384.  
  385.     
  386.     def addExtension(self, item):
  387.         self.extensions.append(item)
  388.  
  389.  
  390.  
  391. class Message(Element):
  392.     
  393.     def __init__(self, name, documentation = ''):
  394.         Element.__init__(self, name, documentation)
  395.         self.parts = Collection(self)
  396.  
  397.     
  398.     def addPart(self, name, type = None, element = None):
  399.         if self.parts.has_key(name):
  400.             raise WSDLError('Duplicate message part element: %s' % name)
  401.         
  402.         if type is None and element is None:
  403.             raise WSDLError('Missing type or element attribute for part: %s' % name)
  404.         
  405.         item = MessagePart(name)
  406.         item.element = element
  407.         item.type = type
  408.         self.parts[name] = item
  409.         return item
  410.  
  411.     
  412.     def load(self, elements):
  413.         for element in elements:
  414.             name = DOM.getAttr(element, 'name')
  415.             part = MessagePart(name)
  416.             self.parts[name] = part
  417.             elemref = DOM.getAttr(element, 'element', default = None)
  418.             typeref = DOM.getAttr(element, 'type', default = None)
  419.             if typeref is None and elemref is None:
  420.                 raise WSDLError('No type or element attribute for part: %s' % name)
  421.             
  422.             if typeref is not None:
  423.                 part.type = ParseTypeRef(typeref, element)
  424.             
  425.             if elemref is not None:
  426.                 part.element = ParseTypeRef(elemref, element)
  427.                 continue
  428.         
  429.  
  430.     
  431.     def toDom(self):
  432.         wsdl = self.getWSDL()
  433.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  434.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'message')
  435.         epc.setAttributeNS(None, 'name', self.name)
  436.         for part in self.parts:
  437.             part.toDom(epc._getNode())
  438.         
  439.  
  440.  
  441.  
  442. class MessagePart(Element):
  443.     
  444.     def __init__(self, name):
  445.         Element.__init__(self, name, '')
  446.         self.element = None
  447.         self.type = None
  448.  
  449.     
  450.     def getTypeDefinition(self):
  451.         wsdl = self.getWSDL()
  452.         (nsuri, name) = self.type
  453.         schema = wsdl.types.get(nsuri, { })
  454.         return schema.get(name)
  455.  
  456.     
  457.     def getElementDeclaration(self):
  458.         wsdl = self.getWSDL()
  459.         (nsuri, name) = self.element
  460.         schema = wsdl.types.get(nsuri, { })
  461.         return schema.get(name)
  462.  
  463.     
  464.     def toDom(self, node):
  465.         wsdl = self.getWSDL()
  466.         ep = ElementProxy(None, node)
  467.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'part')
  468.         epc.setAttributeNS(None, 'name', self.name)
  469.         if self.element is not None:
  470.             (ns, name) = self.element
  471.             prefix = epc.getPrefix(ns)
  472.             epc.setAttributeNS(None, 'element', '%s:%s' % (prefix, name))
  473.         elif self.type is not None:
  474.             (ns, name) = self.type
  475.             prefix = epc.getPrefix(ns)
  476.             epc.setAttributeNS(None, 'type', '%s:%s' % (prefix, name))
  477.         
  478.  
  479.  
  480.  
  481. class PortType(Element):
  482.     
  483.     def __init__(self, name, documentation = ''):
  484.         Element.__init__(self, name, documentation)
  485.         self.operations = Collection(self)
  486.         self.resourceProperties = None
  487.  
  488.     
  489.     def getTargetNamespace(self):
  490.         if not self.targetNamespace:
  491.             pass
  492.         return self.getWSDL().targetNamespace
  493.  
  494.     
  495.     def getResourceProperties(self):
  496.         return self.resourceProperties
  497.  
  498.     
  499.     def addOperation(self, name, documentation = '', parameterOrder = None):
  500.         item = Operation(name, documentation, parameterOrder)
  501.         self.operations[name] = item
  502.         return item
  503.  
  504.     
  505.     def load(self, element):
  506.         self.name = DOM.getAttr(element, 'name')
  507.         self.documentation = GetDocumentation(element)
  508.         self.targetNamespace = DOM.getAttr(element, 'targetNamespace')
  509.         for nsuri in WSRF_V1_2.PROPERTIES.XSD_LIST:
  510.             if DOM.hasAttr(element, 'ResourceProperties', nsuri):
  511.                 rpref = DOM.getAttr(element, 'ResourceProperties', nsuri)
  512.                 self.resourceProperties = ParseQName(rpref, element)
  513.                 continue
  514.         
  515.         NS_WSDL = DOM.GetWSDLUri(self.getWSDL().version)
  516.         elements = DOM.getElements(element, 'operation', NS_WSDL)
  517.         for element in elements:
  518.             name = DOM.getAttr(element, 'name')
  519.             docs = GetDocumentation(element)
  520.             param_order = DOM.getAttr(element, 'parameterOrder', default = None)
  521.             if param_order is not None:
  522.                 param_order = param_order.split(' ')
  523.             
  524.             operation = self.addOperation(name, docs, param_order)
  525.             item = DOM.getElement(element, 'input', None, None)
  526.             if item is not None:
  527.                 name = DOM.getAttr(item, 'name')
  528.                 docs = GetDocumentation(item)
  529.                 msgref = DOM.getAttr(item, 'message')
  530.                 message = ParseQName(msgref, item)
  531.                 for WSA in WSA_LIST:
  532.                     action = DOM.getAttr(item, 'Action', WSA.ADDRESS, None)
  533.                     if action:
  534.                         break
  535.                         continue
  536.                 
  537.                 operation.setInput(message, name, docs, action)
  538.             
  539.             item = DOM.getElement(element, 'output', None, None)
  540.             if item is not None:
  541.                 name = DOM.getAttr(item, 'name')
  542.                 docs = GetDocumentation(item)
  543.                 msgref = DOM.getAttr(item, 'message')
  544.                 message = ParseQName(msgref, item)
  545.                 for WSA in WSA_LIST:
  546.                     action = DOM.getAttr(item, 'Action', WSA.ADDRESS, None)
  547.                     if action:
  548.                         break
  549.                         continue
  550.                 
  551.                 operation.setOutput(message, name, docs, action)
  552.             
  553.             for item in DOM.getElements(element, 'fault', None):
  554.                 name = DOM.getAttr(item, 'name')
  555.                 docs = GetDocumentation(item)
  556.                 msgref = DOM.getAttr(item, 'message')
  557.                 message = ParseQName(msgref, item)
  558.                 for WSA in WSA_LIST:
  559.                     action = DOM.getAttr(item, 'Action', WSA.ADDRESS, None)
  560.                     if action:
  561.                         break
  562.                         continue
  563.                 
  564.                 operation.addFault(message, name, docs, action)
  565.             
  566.         
  567.  
  568.     
  569.     def toDom(self):
  570.         wsdl = self.getWSDL()
  571.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  572.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'portType')
  573.         epc.setAttributeNS(None, 'name', self.name)
  574.         if self.resourceProperties:
  575.             (ns, name) = self.resourceProperties
  576.             prefix = epc.getPrefix(ns)
  577.             epc.setAttributeNS(WSRF.PROPERTIES.LATEST, 'ResourceProperties', '%s:%s' % (prefix, name))
  578.         
  579.         for op in self.operations:
  580.             op.toDom(epc._getNode())
  581.         
  582.  
  583.  
  584.  
  585. class Operation(Element):
  586.     
  587.     def __init__(self, name, documentation = '', parameterOrder = None):
  588.         Element.__init__(self, name, documentation)
  589.         self.parameterOrder = parameterOrder
  590.         self.faults = Collection(self)
  591.         self.input = None
  592.         self.output = None
  593.  
  594.     
  595.     def getWSDL(self):
  596.         return self.parent().parent().parent().parent()
  597.  
  598.     
  599.     def getPortType(self):
  600.         return self.parent().parent()
  601.  
  602.     
  603.     def getInputAction(self):
  604.         return GetWSAActionInput(self)
  605.  
  606.     
  607.     def getInputMessage(self):
  608.         if self.input is None:
  609.             return None
  610.         
  611.         wsdl = self.getPortType().getWSDL()
  612.         return wsdl.messages[self.input.message]
  613.  
  614.     
  615.     def getOutputAction(self):
  616.         return GetWSAActionOutput(self)
  617.  
  618.     
  619.     def getOutputMessage(self):
  620.         if self.output is None:
  621.             return None
  622.         
  623.         wsdl = self.getPortType().getWSDL()
  624.         return wsdl.messages[self.output.message]
  625.  
  626.     
  627.     def getFaultAction(self, name):
  628.         return GetWSAActionFault(self, name)
  629.  
  630.     
  631.     def getFaultMessage(self, name):
  632.         wsdl = self.getPortType().getWSDL()
  633.         return wsdl.messages[self.faults[name].message]
  634.  
  635.     
  636.     def addFault(self, message, name, documentation = '', action = None):
  637.         if self.faults.has_key(name):
  638.             raise WSDLError('Duplicate fault element: %s' % name)
  639.         
  640.         item = MessageRole('fault', message, name, documentation, action)
  641.         self.faults[name] = item
  642.         return item
  643.  
  644.     
  645.     def setInput(self, message, name = '', documentation = '', action = None):
  646.         self.input = MessageRole('input', message, name, documentation, action)
  647.         self.input.parent = weakref.ref(self)
  648.         return self.input
  649.  
  650.     
  651.     def setOutput(self, message, name = '', documentation = '', action = None):
  652.         self.output = MessageRole('output', message, name, documentation, action)
  653.         self.output.parent = weakref.ref(self)
  654.         return self.output
  655.  
  656.     
  657.     def toDom(self, node):
  658.         wsdl = self.getWSDL()
  659.         ep = ElementProxy(None, node)
  660.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'operation')
  661.         epc.setAttributeNS(None, 'name', self.name)
  662.         node = epc._getNode()
  663.         if self.input:
  664.             self.input.toDom(node)
  665.         
  666.         if self.output:
  667.             self.output.toDom(node)
  668.         
  669.         for fault in self.faults:
  670.             fault.toDom(node)
  671.         
  672.  
  673.  
  674.  
  675. class MessageRole(Element):
  676.     
  677.     def __init__(self, type, message, name = '', documentation = '', action = None):
  678.         Element.__init__(self, name, documentation)
  679.         self.message = message
  680.         self.type = type
  681.         self.action = action
  682.  
  683.     
  684.     def getWSDL(self):
  685.         parent = self
  686.         while isinstance(parent, WSDL):
  687.             return parent
  688.         
  689.         try:
  690.             parent = parent.parent()
  691.         continue
  692.         break
  693.         continue
  694.  
  695.         continue
  696.  
  697.     
  698.     def getMessage(self):
  699.         wsdl = self.getWSDL()
  700.         return wsdl.messages[self.message]
  701.  
  702.     
  703.     def toDom(self, node):
  704.         wsdl = self.getWSDL()
  705.         ep = ElementProxy(None, node)
  706.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), self.type)
  707.         if not isinstance(self.message, basestring) and len(self.message) == 2:
  708.             (ns, name) = self.message
  709.             prefix = epc.getPrefix(ns)
  710.             epc.setAttributeNS(None, 'message', '%s:%s' % (prefix, name))
  711.         else:
  712.             epc.setAttributeNS(None, 'message', self.message)
  713.         if self.action:
  714.             epc.setAttributeNS(WSA.ADDRESS, 'Action', self.action)
  715.         
  716.         if self.name:
  717.             epc.setAttributeNS(None, 'name', self.name)
  718.         
  719.  
  720.  
  721.  
  722. class Binding(Element):
  723.     
  724.     def __init__(self, name, type, documentation = ''):
  725.         Element.__init__(self, name, documentation)
  726.         self.operations = Collection(self)
  727.         self.type = type
  728.  
  729.     
  730.     def getPortType(self):
  731.         return self.getWSDL().portTypes[self.type]
  732.  
  733.     
  734.     def findBinding(self, kind):
  735.         for item in self.extensions:
  736.             if isinstance(item, kind):
  737.                 return item
  738.                 continue
  739.         
  740.  
  741.     
  742.     def findBindings(self, kind):
  743.         return _[1]
  744.  
  745.     
  746.     def addOperationBinding(self, name, documentation = ''):
  747.         item = OperationBinding(name, documentation)
  748.         self.operations[name] = item
  749.         return item
  750.  
  751.     
  752.     def load(self, elements):
  753.         for element in elements:
  754.             name = DOM.getAttr(element, 'name')
  755.             docs = GetDocumentation(element)
  756.             opbinding = self.addOperationBinding(name, docs)
  757.             opbinding.load_ex(GetExtensions(element))
  758.             item = DOM.getElement(element, 'input', None, None)
  759.             if item is not None:
  760.                 mbinding = MessageRoleBinding('input')
  761.                 mbinding.documentation = GetDocumentation(item)
  762.                 opbinding.input = mbinding
  763.                 mbinding.load_ex(GetExtensions(item))
  764.                 mbinding.parent = weakref.ref(opbinding)
  765.             
  766.             item = DOM.getElement(element, 'output', None, None)
  767.             if item is not None:
  768.                 mbinding = MessageRoleBinding('output')
  769.                 mbinding.documentation = GetDocumentation(item)
  770.                 opbinding.output = mbinding
  771.                 mbinding.load_ex(GetExtensions(item))
  772.                 mbinding.parent = weakref.ref(opbinding)
  773.             
  774.             for item in DOM.getElements(element, 'fault', None):
  775.                 name = DOM.getAttr(item, 'name')
  776.                 mbinding = MessageRoleBinding('fault', name)
  777.                 mbinding.documentation = GetDocumentation(item)
  778.                 opbinding.faults[name] = mbinding
  779.                 mbinding.load_ex(GetExtensions(item))
  780.                 mbinding.parent = weakref.ref(opbinding)
  781.             
  782.         
  783.  
  784.     
  785.     def load_ex(self, elements):
  786.         for e in elements:
  787.             ns = e.namespaceURI
  788.             name = e.localName
  789.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'binding':
  790.                 transport = DOM.getAttr(e, 'transport', default = None)
  791.                 style = DOM.getAttr(e, 'style', default = 'document')
  792.                 ob = SoapBinding(transport, style)
  793.                 self.addExtension(ob)
  794.                 continue
  795.                 continue
  796.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'binding':
  797.                 verb = DOM.getAttr(e, 'verb')
  798.                 ob = HttpBinding(verb)
  799.                 self.addExtension(ob)
  800.                 continue
  801.                 continue
  802.             self.addExtension(e)
  803.         
  804.  
  805.     
  806.     def toDom(self):
  807.         wsdl = self.getWSDL()
  808.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  809.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'binding')
  810.         epc.setAttributeNS(None, 'name', self.name)
  811.         (ns, name) = self.type
  812.         prefix = epc.getPrefix(ns)
  813.         epc.setAttributeNS(None, 'type', '%s:%s' % (prefix, name))
  814.         node = epc._getNode()
  815.         for ext in self.extensions:
  816.             ext.toDom(node)
  817.         
  818.         for op_binding in self.operations:
  819.             op_binding.toDom(node)
  820.         
  821.  
  822.  
  823.  
  824. class OperationBinding(Element):
  825.     
  826.     def __init__(self, name, documentation = ''):
  827.         Element.__init__(self, name, documentation)
  828.         self.input = None
  829.         self.output = None
  830.         self.faults = Collection(self)
  831.  
  832.     
  833.     def getBinding(self):
  834.         return self.parent().parent()
  835.  
  836.     
  837.     def getOperation(self):
  838.         return self.getBinding().getPortType().operations[self.name]
  839.  
  840.     
  841.     def findBinding(self, kind):
  842.         for item in self.extensions:
  843.             if isinstance(item, kind):
  844.                 return item
  845.                 continue
  846.         
  847.  
  848.     
  849.     def findBindings(self, kind):
  850.         return _[1]
  851.  
  852.     
  853.     def addInputBinding(self, binding):
  854.         if self.input is None:
  855.             self.input = MessageRoleBinding('input')
  856.             self.input.parent = weakref.ref(self)
  857.         
  858.         self.input.addExtension(binding)
  859.         return binding
  860.  
  861.     
  862.     def addOutputBinding(self, binding):
  863.         if self.output is None:
  864.             self.output = MessageRoleBinding('output')
  865.             self.output.parent = weakref.ref(self)
  866.         
  867.         self.output.addExtension(binding)
  868.         return binding
  869.  
  870.     
  871.     def addFaultBinding(self, name, binding):
  872.         fault = self.get(name, None)
  873.         if fault is None:
  874.             fault = MessageRoleBinding('fault', name)
  875.         
  876.         fault.addExtension(binding)
  877.         return binding
  878.  
  879.     
  880.     def load_ex(self, elements):
  881.         for e in elements:
  882.             ns = e.namespaceURI
  883.             name = e.localName
  884.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'operation':
  885.                 soapaction = DOM.getAttr(e, 'soapAction', default = None)
  886.                 style = DOM.getAttr(e, 'style', default = None)
  887.                 ob = SoapOperationBinding(soapaction, style)
  888.                 self.addExtension(ob)
  889.                 continue
  890.                 continue
  891.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'operation':
  892.                 location = DOM.getAttr(e, 'location')
  893.                 ob = HttpOperationBinding(location)
  894.                 self.addExtension(ob)
  895.                 continue
  896.                 continue
  897.             self.addExtension(e)
  898.         
  899.  
  900.     
  901.     def toDom(self, node):
  902.         wsdl = self.getWSDL()
  903.         ep = ElementProxy(None, node)
  904.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'operation')
  905.         epc.setAttributeNS(None, 'name', self.name)
  906.         node = epc._getNode()
  907.         for ext in self.extensions:
  908.             ext.toDom(node)
  909.         
  910.         if self.input:
  911.             self.input.toDom(node)
  912.         
  913.         if self.output:
  914.             self.output.toDom(node)
  915.         
  916.         for fault in self.faults:
  917.             fault.toDom(node)
  918.         
  919.  
  920.  
  921.  
  922. class MessageRoleBinding(Element):
  923.     
  924.     def __init__(self, type, name = '', documentation = ''):
  925.         Element.__init__(self, name, documentation)
  926.         self.type = type
  927.  
  928.     
  929.     def findBinding(self, kind):
  930.         for item in self.extensions:
  931.             if isinstance(item, kind):
  932.                 return item
  933.                 continue
  934.         
  935.  
  936.     
  937.     def findBindings(self, kind):
  938.         return _[1]
  939.  
  940.     
  941.     def load_ex(self, elements):
  942.         for e in elements:
  943.             ns = e.namespaceURI
  944.             name = e.localName
  945.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'body':
  946.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  947.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  948.                 parts = DOM.getAttr(e, 'parts', default = None)
  949.                 use = DOM.getAttr(e, 'use', default = None)
  950.                 if use is None:
  951.                     raise WSDLError('Invalid soap:body binding element.')
  952.                 
  953.                 ob = SoapBodyBinding(use, namespace, encstyle, parts)
  954.                 self.addExtension(ob)
  955.                 continue
  956.                 continue
  957.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'fault':
  958.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  959.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  960.                 name = DOM.getAttr(e, 'name', default = None)
  961.                 use = DOM.getAttr(e, 'use', default = None)
  962.                 if use is None or name is None:
  963.                     raise WSDLError('Invalid soap:fault binding element.')
  964.                 
  965.                 ob = SoapFaultBinding(name, use, namespace, encstyle)
  966.                 self.addExtension(ob)
  967.                 continue
  968.                 continue
  969.             if ns in DOM.NS_SOAP_BINDING_ALL and name in ('header', 'headerfault'):
  970.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  971.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  972.                 message = DOM.getAttr(e, 'message')
  973.                 part = DOM.getAttr(e, 'part')
  974.                 use = DOM.getAttr(e, 'use')
  975.                 if name == 'header':
  976.                     _class = SoapHeaderBinding
  977.                 else:
  978.                     _class = SoapHeaderFaultBinding
  979.                 message = ParseQName(message, e)
  980.                 ob = _class(message, part, use, namespace, encstyle)
  981.                 self.addExtension(ob)
  982.                 continue
  983.                 continue
  984.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'urlReplacement':
  985.                 ob = HttpUrlReplacementBinding()
  986.                 self.addExtension(ob)
  987.                 continue
  988.                 continue
  989.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'urlEncoded':
  990.                 ob = HttpUrlEncodedBinding()
  991.                 self.addExtension(ob)
  992.                 continue
  993.                 continue
  994.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'multipartRelated':
  995.                 ob = MimeMultipartRelatedBinding()
  996.                 self.addExtension(ob)
  997.                 ob.load_ex(GetExtensions(e))
  998.                 continue
  999.                 continue
  1000.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'content':
  1001.                 part = DOM.getAttr(e, 'part', default = None)
  1002.                 type = DOM.getAttr(e, 'type', default = None)
  1003.                 ob = MimeContentBinding(part, type)
  1004.                 self.addExtension(ob)
  1005.                 continue
  1006.                 continue
  1007.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'mimeXml':
  1008.                 part = DOM.getAttr(e, 'part', default = None)
  1009.                 ob = MimeXmlBinding(part)
  1010.                 self.addExtension(ob)
  1011.                 continue
  1012.                 continue
  1013.             self.addExtension(e)
  1014.         
  1015.  
  1016.     
  1017.     def toDom(self, node):
  1018.         wsdl = self.getWSDL()
  1019.         ep = ElementProxy(None, node)
  1020.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), self.type)
  1021.         node = epc._getNode()
  1022.         for item in self.extensions:
  1023.             if item:
  1024.                 item.toDom(node)
  1025.                 continue
  1026.         
  1027.  
  1028.  
  1029.  
  1030. class Service(Element):
  1031.     
  1032.     def __init__(self, name, documentation = ''):
  1033.         Element.__init__(self, name, documentation)
  1034.         self.ports = Collection(self)
  1035.  
  1036.     
  1037.     def getWSDL(self):
  1038.         return self.parent().parent()
  1039.  
  1040.     
  1041.     def addPort(self, name, binding, documentation = ''):
  1042.         item = Port(name, binding, documentation)
  1043.         self.ports[name] = item
  1044.         return item
  1045.  
  1046.     
  1047.     def load(self, elements):
  1048.         for element in elements:
  1049.             name = DOM.getAttr(element, 'name', default = None)
  1050.             docs = GetDocumentation(element)
  1051.             binding = DOM.getAttr(element, 'binding', default = None)
  1052.             if name is None or binding is None:
  1053.                 raise WSDLError('Invalid port element.')
  1054.             
  1055.             binding = ParseQName(binding, element)
  1056.             port = self.addPort(name, binding, docs)
  1057.             port.load_ex(GetExtensions(element))
  1058.         
  1059.  
  1060.     
  1061.     def load_ex(self, elements):
  1062.         for e in elements:
  1063.             self.addExtension(e)
  1064.         
  1065.  
  1066.     
  1067.     def toDom(self):
  1068.         wsdl = self.getWSDL()
  1069.         ep = ElementProxy(None, DOM.getElement(wsdl.document, None))
  1070.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'service')
  1071.         epc.setAttributeNS(None, 'name', self.name)
  1072.         node = epc._getNode()
  1073.         for port in self.ports:
  1074.             port.toDom(node)
  1075.         
  1076.  
  1077.  
  1078.  
  1079. class Port(Element):
  1080.     
  1081.     def __init__(self, name, binding, documentation = ''):
  1082.         Element.__init__(self, name, documentation)
  1083.         self.binding = binding
  1084.  
  1085.     
  1086.     def getService(self):
  1087.         return self.parent().parent()
  1088.  
  1089.     
  1090.     def getBinding(self):
  1091.         wsdl = self.getService().getWSDL()
  1092.         return wsdl.bindings[self.binding]
  1093.  
  1094.     
  1095.     def getPortType(self):
  1096.         wsdl = self.getService().getWSDL()
  1097.         binding = wsdl.bindings[self.binding]
  1098.         return wsdl.portTypes[binding.type]
  1099.  
  1100.     
  1101.     def getAddressBinding(self):
  1102.         for item in self.extensions:
  1103.             if isinstance(item, SoapAddressBinding) or isinstance(item, HttpAddressBinding):
  1104.                 return item
  1105.                 continue
  1106.         
  1107.         raise WSDLError('No address binding found in port.')
  1108.  
  1109.     
  1110.     def load_ex(self, elements):
  1111.         for e in elements:
  1112.             ns = e.namespaceURI
  1113.             name = e.localName
  1114.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'address':
  1115.                 location = DOM.getAttr(e, 'location', default = None)
  1116.                 ob = SoapAddressBinding(location)
  1117.                 self.addExtension(ob)
  1118.                 continue
  1119.                 continue
  1120.             if ns in DOM.NS_HTTP_BINDING_ALL and name == 'address':
  1121.                 location = DOM.getAttr(e, 'location', default = None)
  1122.                 ob = HttpAddressBinding(location)
  1123.                 self.addExtension(ob)
  1124.                 continue
  1125.                 continue
  1126.             self.addExtension(e)
  1127.         
  1128.  
  1129.     
  1130.     def toDom(self, node):
  1131.         wsdl = self.getWSDL()
  1132.         ep = ElementProxy(None, node)
  1133.         epc = ep.createAppendElement(DOM.GetWSDLUri(wsdl.version), 'port')
  1134.         epc.setAttributeNS(None, 'name', self.name)
  1135.         (ns, name) = self.binding
  1136.         prefix = epc.getPrefix(ns)
  1137.         epc.setAttributeNS(None, 'binding', '%s:%s' % (prefix, name))
  1138.         node = epc._getNode()
  1139.         for ext in self.extensions:
  1140.             ext.toDom(node)
  1141.         
  1142.  
  1143.  
  1144.  
  1145. class SoapBinding:
  1146.     
  1147.     def __init__(self, transport, style = 'rpc'):
  1148.         self.transport = transport
  1149.         self.style = style
  1150.  
  1151.     
  1152.     def getWSDL(self):
  1153.         return self.parent().getWSDL()
  1154.  
  1155.     
  1156.     def toDom(self, node):
  1157.         wsdl = self.getWSDL()
  1158.         ep = ElementProxy(None, node)
  1159.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'binding')
  1160.         if self.transport:
  1161.             epc.setAttributeNS(None, 'transport', self.transport)
  1162.         
  1163.         if self.style:
  1164.             epc.setAttributeNS(None, 'style', self.style)
  1165.         
  1166.  
  1167.  
  1168.  
  1169. class SoapAddressBinding:
  1170.     
  1171.     def __init__(self, location):
  1172.         self.location = location
  1173.  
  1174.     
  1175.     def getWSDL(self):
  1176.         return self.parent().getWSDL()
  1177.  
  1178.     
  1179.     def toDom(self, node):
  1180.         wsdl = self.getWSDL()
  1181.         ep = ElementProxy(None, node)
  1182.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'address')
  1183.         epc.setAttributeNS(None, 'location', self.location)
  1184.  
  1185.  
  1186.  
  1187. class SoapOperationBinding:
  1188.     
  1189.     def __init__(self, soapAction = None, style = None):
  1190.         self.soapAction = soapAction
  1191.         self.style = style
  1192.  
  1193.     
  1194.     def getWSDL(self):
  1195.         return self.parent().getWSDL()
  1196.  
  1197.     
  1198.     def toDom(self, node):
  1199.         wsdl = self.getWSDL()
  1200.         ep = ElementProxy(None, node)
  1201.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'operation')
  1202.         if self.soapAction:
  1203.             epc.setAttributeNS(None, 'soapAction', self.soapAction)
  1204.         
  1205.         if self.style:
  1206.             epc.setAttributeNS(None, 'style', self.style)
  1207.         
  1208.  
  1209.  
  1210.  
  1211. class SoapBodyBinding:
  1212.     
  1213.     def __init__(self, use, namespace = None, encodingStyle = None, parts = None):
  1214.         if use not in ('literal', 'encoded'):
  1215.             raise WSDLError('Invalid use attribute value: %s' % use)
  1216.         
  1217.         self.encodingStyle = encodingStyle
  1218.         self.namespace = namespace
  1219.         if type(parts) in (type(''), type(u'')):
  1220.             parts = parts.split()
  1221.         
  1222.         self.parts = parts
  1223.         self.use = use
  1224.  
  1225.     
  1226.     def getWSDL(self):
  1227.         return self.parent().getWSDL()
  1228.  
  1229.     
  1230.     def toDom(self, node):
  1231.         wsdl = self.getWSDL()
  1232.         ep = ElementProxy(None, node)
  1233.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'body')
  1234.         epc.setAttributeNS(None, 'use', self.use)
  1235.         epc.setAttributeNS(None, 'namespace', self.namespace)
  1236.  
  1237.  
  1238.  
  1239. class SoapFaultBinding:
  1240.     
  1241.     def __init__(self, name, use, namespace = None, encodingStyle = None):
  1242.         if use not in ('literal', 'encoded'):
  1243.             raise WSDLError('Invalid use attribute value: %s' % use)
  1244.         
  1245.         self.encodingStyle = encodingStyle
  1246.         self.namespace = namespace
  1247.         self.name = name
  1248.         self.use = use
  1249.  
  1250.     
  1251.     def getWSDL(self):
  1252.         return self.parent().getWSDL()
  1253.  
  1254.     
  1255.     def toDom(self, node):
  1256.         wsdl = self.getWSDL()
  1257.         ep = ElementProxy(None, node)
  1258.         epc = ep.createAppendElement(DOM.GetWSDLSoapBindingUri(wsdl.version), 'body')
  1259.         epc.setAttributeNS(None, 'use', self.use)
  1260.         epc.setAttributeNS(None, 'name', self.name)
  1261.         if self.namespace is not None:
  1262.             epc.setAttributeNS(None, 'namespace', self.namespace)
  1263.         
  1264.         if self.encodingStyle is not None:
  1265.             epc.setAttributeNS(None, 'encodingStyle', self.encodingStyle)
  1266.         
  1267.  
  1268.  
  1269.  
  1270. class SoapHeaderBinding:
  1271.     
  1272.     def __init__(self, message, part, use, namespace = None, encodingStyle = None):
  1273.         if use not in ('literal', 'encoded'):
  1274.             raise WSDLError('Invalid use attribute value: %s' % use)
  1275.         
  1276.         self.encodingStyle = encodingStyle
  1277.         self.namespace = namespace
  1278.         self.message = message
  1279.         self.part = part
  1280.         self.use = use
  1281.  
  1282.     tagname = 'header'
  1283.  
  1284.  
  1285. class SoapHeaderFaultBinding(SoapHeaderBinding):
  1286.     tagname = 'headerfault'
  1287.  
  1288.  
  1289. class HttpBinding:
  1290.     
  1291.     def __init__(self, verb):
  1292.         self.verb = verb
  1293.  
  1294.  
  1295.  
  1296. class HttpAddressBinding:
  1297.     
  1298.     def __init__(self, location):
  1299.         self.location = location
  1300.  
  1301.  
  1302.  
  1303. class HttpOperationBinding:
  1304.     
  1305.     def __init__(self, location):
  1306.         self.location = location
  1307.  
  1308.  
  1309.  
  1310. class HttpUrlReplacementBinding:
  1311.     pass
  1312.  
  1313.  
  1314. class HttpUrlEncodedBinding:
  1315.     pass
  1316.  
  1317.  
  1318. class MimeContentBinding:
  1319.     
  1320.     def __init__(self, part = None, type = None):
  1321.         self.part = part
  1322.         self.type = type
  1323.  
  1324.  
  1325.  
  1326. class MimeXmlBinding:
  1327.     
  1328.     def __init__(self, part = None):
  1329.         self.part = part
  1330.  
  1331.  
  1332.  
  1333. class MimeMultipartRelatedBinding:
  1334.     
  1335.     def __init__(self):
  1336.         self.parts = []
  1337.  
  1338.     
  1339.     def load_ex(self, elements):
  1340.         for e in elements:
  1341.             ns = e.namespaceURI
  1342.             name = e.localName
  1343.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'part':
  1344.                 self.parts.append(MimePartBinding())
  1345.                 continue
  1346.                 continue
  1347.         
  1348.  
  1349.  
  1350.  
  1351. class MimePartBinding:
  1352.     
  1353.     def __init__(self):
  1354.         self.items = []
  1355.  
  1356.     
  1357.     def load_ex(self, elements):
  1358.         for e in elements:
  1359.             ns = e.namespaceURI
  1360.             name = e.localName
  1361.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'content':
  1362.                 part = DOM.getAttr(e, 'part', default = None)
  1363.                 type = DOM.getAttr(e, 'type', default = None)
  1364.                 ob = MimeContentBinding(part, type)
  1365.                 self.items.append(ob)
  1366.                 continue
  1367.                 continue
  1368.             if ns in DOM.NS_MIME_BINDING_ALL and name == 'mimeXml':
  1369.                 part = DOM.getAttr(e, 'part', default = None)
  1370.                 ob = MimeXmlBinding(part)
  1371.                 self.items.append(ob)
  1372.                 continue
  1373.                 continue
  1374.             if ns in DOM.NS_SOAP_BINDING_ALL and name == 'body':
  1375.                 encstyle = DOM.getAttr(e, 'encodingStyle', default = None)
  1376.                 namespace = DOM.getAttr(e, 'namespace', default = None)
  1377.                 parts = DOM.getAttr(e, 'parts', default = None)
  1378.                 use = DOM.getAttr(e, 'use', default = None)
  1379.                 if use is None:
  1380.                     raise WSDLError('Invalid soap:body binding element.')
  1381.                 
  1382.                 ob = SoapBodyBinding(use, namespace, encstyle, parts)
  1383.                 self.items.append(ob)
  1384.                 continue
  1385.                 continue
  1386.         
  1387.  
  1388.  
  1389.  
  1390. class WSDLError(Exception):
  1391.     pass
  1392.  
  1393.  
  1394. def DeclareNSPrefix(writer, prefix, nsuri):
  1395.     if writer.hasNSPrefix(nsuri):
  1396.         return None
  1397.     
  1398.     writer.declareNSPrefix(prefix, nsuri)
  1399.  
  1400.  
  1401. def ParseTypeRef(value, element):
  1402.     parts = value.split(':', 1)
  1403.     if len(parts) == 1:
  1404.         return (DOM.findTargetNS(element), value)
  1405.     
  1406.     nsuri = DOM.findNamespaceURI(parts[0], element)
  1407.     return (nsuri, parts[1])
  1408.  
  1409.  
  1410. def ParseQName(value, element):
  1411.     nameref = value.split(':', 1)
  1412.     if len(nameref) == 2:
  1413.         nsuri = DOM.findNamespaceURI(nameref[0], element)
  1414.         name = nameref[-1]
  1415.     else:
  1416.         nsuri = DOM.findTargetNS(element)
  1417.         name = nameref[-1]
  1418.     return (nsuri, name)
  1419.  
  1420.  
  1421. def GetDocumentation(element):
  1422.     docnode = DOM.getElement(element, 'documentation', None, None)
  1423.     if docnode is not None:
  1424.         return DOM.getElementText(docnode)
  1425.     
  1426.     return ''
  1427.  
  1428.  
  1429. def GetExtensions(element):
  1430.     return _[1]
  1431.  
  1432.  
  1433. def GetWSAActionFault(operation, name):
  1434.     attr = operation.faults[name].action
  1435.     if attr is not None:
  1436.         return attr
  1437.     
  1438.     return WSA.FAULT
  1439.  
  1440.  
  1441. def GetWSAActionInput(operation):
  1442.     attr = operation.input.action
  1443.     if attr is not None:
  1444.         return attr
  1445.     
  1446.     portType = operation.getPortType()
  1447.     targetNamespace = portType.getTargetNamespace()
  1448.     ptName = portType.name
  1449.     msgName = operation.input.name
  1450.     if not msgName:
  1451.         msgName = operation.name + 'Request'
  1452.     
  1453.     if targetNamespace.endswith('/'):
  1454.         return '%s%s/%s' % (targetNamespace, ptName, msgName)
  1455.     
  1456.     return '%s/%s/%s' % (targetNamespace, ptName, msgName)
  1457.  
  1458.  
  1459. def GetWSAActionOutput(operation):
  1460.     attr = operation.output.action
  1461.     if attr is not None:
  1462.         return attr
  1463.     
  1464.     targetNamespace = operation.getPortType().getTargetNamespace()
  1465.     ptName = operation.getPortType().name
  1466.     msgName = operation.output.name
  1467.     if not msgName:
  1468.         msgName = operation.name + 'Response'
  1469.     
  1470.     if targetNamespace.endswith('/'):
  1471.         return '%s%s/%s' % (targetNamespace, ptName, msgName)
  1472.     
  1473.     return '%s/%s/%s' % (targetNamespace, ptName, msgName)
  1474.  
  1475.  
  1476. def FindExtensions(object, kind, t_type = type(())):
  1477.     return _[2]
  1478.  
  1479.  
  1480. def FindExtension(object, kind, t_type = type(())):
  1481.     if isinstance(kind, t_type):
  1482.         (namespaceURI, name) = kind
  1483.         for item in object.extensions:
  1484.             if hasattr(item, 'nodeType') and DOM.nsUriMatch(namespaceURI, item.namespaceURI) and item.name == name:
  1485.                 return item
  1486.                 continue
  1487.         
  1488.     else:
  1489.         for item in object.extensions:
  1490.             if isinstance(item, kind):
  1491.                 return item
  1492.                 continue
  1493.         
  1494.  
  1495.  
  1496. class SOAPCallInfo:
  1497.     
  1498.     def __init__(self, methodName):
  1499.         self.methodName = methodName
  1500.         self.inheaders = []
  1501.         self.outheaders = []
  1502.         self.inparams = []
  1503.         self.outparams = []
  1504.         self.retval = None
  1505.  
  1506.     encodingStyle = DOM.NS_SOAP_ENC
  1507.     documentation = ''
  1508.     soapAction = None
  1509.     transport = None
  1510.     namespace = None
  1511.     location = None
  1512.     use = 'encoded'
  1513.     style = 'rpc'
  1514.     
  1515.     def addInParameter(self, name, type, namespace = None, element_type = 0):
  1516.         parameter = ParameterInfo(name, type, namespace, element_type)
  1517.         self.inparams.append(parameter)
  1518.         return parameter
  1519.  
  1520.     
  1521.     def addOutParameter(self, name, type, namespace = None, element_type = 0):
  1522.         parameter = ParameterInfo(name, type, namespace, element_type)
  1523.         self.outparams.append(parameter)
  1524.         return parameter
  1525.  
  1526.     
  1527.     def setReturnParameter(self, name, type, namespace = None, element_type = 0):
  1528.         parameter = ParameterInfo(name, type, namespace, element_type)
  1529.         self.retval = parameter
  1530.         return parameter
  1531.  
  1532.     
  1533.     def addInHeaderInfo(self, name, type, namespace, element_type = 0, mustUnderstand = 0):
  1534.         headerinfo = HeaderInfo(name, type, namespace, element_type)
  1535.         if mustUnderstand:
  1536.             headerinfo.mustUnderstand = 1
  1537.         
  1538.         self.inheaders.append(headerinfo)
  1539.         return headerinfo
  1540.  
  1541.     
  1542.     def addOutHeaderInfo(self, name, type, namespace, element_type = 0, mustUnderstand = 0):
  1543.         headerinfo = HeaderInfo(name, type, namespace, element_type)
  1544.         if mustUnderstand:
  1545.             headerinfo.mustUnderstand = 1
  1546.         
  1547.         self.outheaders.append(headerinfo)
  1548.         return headerinfo
  1549.  
  1550.     
  1551.     def getInParameters(self):
  1552.         return self.inparams
  1553.  
  1554.     
  1555.     def getOutParameters(self):
  1556.         return self.outparams
  1557.  
  1558.     
  1559.     def getReturnParameter(self):
  1560.         return self.retval
  1561.  
  1562.     
  1563.     def getInHeaders(self):
  1564.         return self.inheaders
  1565.  
  1566.     
  1567.     def getOutHeaders(self):
  1568.         return self.outheaders
  1569.  
  1570.  
  1571.  
  1572. class ParameterInfo:
  1573.     
  1574.     def __init__(self, name, type, namespace = None, element_type = 0):
  1575.         if element_type:
  1576.             self.element_type = 1
  1577.         
  1578.         if namespace is not None:
  1579.             self.namespace = namespace
  1580.         
  1581.         self.name = name
  1582.         self.type = type
  1583.  
  1584.     element_type = 0
  1585.     namespace = None
  1586.     default = None
  1587.  
  1588.  
  1589. class HeaderInfo(ParameterInfo):
  1590.     
  1591.     def __init__(self, name, type, namespace, element_type = None):
  1592.         ParameterInfo.__init__(self, name, type, namespace, element_type)
  1593.  
  1594.     mustUnderstand = 0
  1595.     actor = None
  1596.  
  1597.  
  1598. def callInfoFromWSDL(port, name):
  1599.     wsdl = port.getService().getWSDL()
  1600.     binding = port.getBinding()
  1601.     portType = binding.getPortType()
  1602.     operation = portType.operations[name]
  1603.     opbinding = binding.operations[name]
  1604.     messages = wsdl.messages
  1605.     callinfo = SOAPCallInfo(name)
  1606.     addrbinding = port.getAddressBinding()
  1607.     if not isinstance(addrbinding, SoapAddressBinding):
  1608.         raise ValueError, 'Unsupported binding type.'
  1609.     
  1610.     callinfo.location = addrbinding.location
  1611.     soapbinding = binding.findBinding(SoapBinding)
  1612.     if soapbinding is None:
  1613.         raise ValueError, 'Missing soap:binding element.'
  1614.     
  1615.     callinfo.transport = soapbinding.transport
  1616.     if not soapbinding.style:
  1617.         pass
  1618.     callinfo.style = 'document'
  1619.     soap_op_binding = opbinding.findBinding(SoapOperationBinding)
  1620.     if soap_op_binding is not None:
  1621.         callinfo.soapAction = soap_op_binding.soapAction
  1622.         if not soap_op_binding.style:
  1623.             pass
  1624.         callinfo.style = callinfo.style
  1625.     
  1626.     parameterOrder = operation.parameterOrder
  1627.     if operation.input is not None:
  1628.         message = messages[operation.input.message]
  1629.         msgrole = opbinding.input
  1630.         mime = msgrole.findBinding(MimeMultipartRelatedBinding)
  1631.         if mime is not None:
  1632.             raise ValueError, 'Mime bindings are not supported.'
  1633.         else:
  1634.             for item in msgrole.findBindings(SoapHeaderBinding):
  1635.                 part = messages[item.message].parts[item.part]
  1636.                 if not part.element:
  1637.                     pass
  1638.                 if not part.element or 1:
  1639.                     pass
  1640.                 header = callinfo.addInHeaderInfo(part.name, part.type, item.namespace, element_type = 0)
  1641.                 header.encodingStyle = item.encodingStyle
  1642.             
  1643.             body = msgrole.findBinding(SoapBodyBinding)
  1644.             if body is None:
  1645.                 raise ValueError, 'Missing soap:body binding.'
  1646.             
  1647.             callinfo.encodingStyle = body.encodingStyle
  1648.             callinfo.namespace = body.namespace
  1649.             callinfo.use = body.use
  1650.             if body.parts is not None:
  1651.                 parts = []
  1652.                 for name in body.parts:
  1653.                     parts.append(message.parts[name])
  1654.                 
  1655.             else:
  1656.                 parts = message.parts.values()
  1657.             for part in parts:
  1658.                 if not part.element:
  1659.                     pass
  1660.                 if not part.element or 1:
  1661.                     pass
  1662.                 callinfo.addInParameter(part.name, part.type, element_type = 0)
  1663.             
  1664.     
  1665.     if operation.output is not None:
  1666.         
  1667.         try:
  1668.             message = messages[operation.output.message]
  1669.         except KeyError:
  1670.             if self.strict:
  1671.                 raise RuntimeError('Recieved message not defined in the WSDL schema: %s' % operation.output.message)
  1672.             else:
  1673.                 message = wsdl.addMessage(operation.output.message)
  1674.                 print 'Warning:', 'Recieved message not defined in the WSDL schema.', 'Adding it.'
  1675.                 print 'Message:', operation.output.message
  1676.         except:
  1677.             self.strict
  1678.  
  1679.         msgrole = opbinding.output
  1680.         mime = msgrole.findBinding(MimeMultipartRelatedBinding)
  1681.         if mime is not None:
  1682.             raise ValueError, 'Mime bindings are not supported.'
  1683.         else:
  1684.             for item in msgrole.findBindings(SoapHeaderBinding):
  1685.                 part = messages[item.message].parts[item.part]
  1686.                 if not part.element:
  1687.                     pass
  1688.                 if not part.element or 1:
  1689.                     pass
  1690.                 header = callinfo.addOutHeaderInfo(part.name, part.type, item.namespace, element_type = 0)
  1691.                 header.encodingStyle = item.encodingStyle
  1692.             
  1693.             body = msgrole.findBinding(SoapBodyBinding)
  1694.             if body is None:
  1695.                 raise ValueError, 'Missing soap:body binding.'
  1696.             
  1697.             callinfo.encodingStyle = body.encodingStyle
  1698.             callinfo.namespace = body.namespace
  1699.             callinfo.use = body.use
  1700.             if body.parts is not None:
  1701.                 parts = []
  1702.                 for name in body.parts:
  1703.                     parts.append(message.parts[name])
  1704.                 
  1705.             else:
  1706.                 parts = message.parts.values()
  1707.             if parts:
  1708.                 for part in parts:
  1709.                     if not part.element:
  1710.                         pass
  1711.                     if not part.element or 1:
  1712.                         pass
  1713.                     callinfo.addOutParameter(part.name, part.type, element_type = 0)
  1714.                 
  1715.             
  1716.     
  1717.     return callinfo
  1718.  
  1719.